package com.kexun.servlet.student;

import com.kexun.pojo.Student;
import com.kexun.pojo.User;
import com.kexun.service.StuService;
import com.kexun.service.impl.StuServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/ServletStudentInfo")
public class ServletStudentInfo extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        //查询用户的信息，先获取用户登录的账号（session)
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        String userNum = user.getUserNum();
        //调用业务逻辑
        StuService ss = new StuServiceImpl();
        Student stu = ss.findStuInfo(userNum);
        if(stu!=null){
            session.setAttribute("stu",stu);
            request.getRequestDispatcher("student/stuInfo.jsp").forward(request,response);

        }else{

        }



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
